<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.UserMethods"%>
	<div class="page-header">
	<h2 class="page-title">Nowe wydarzenie</h2>
</div>
<script>


$.fn.setNow = function (onlyBlank) {
	  var now = new Date($.now())
	    , year
	    , month
	    , date
	    , hours
	    , minutes
	    , seconds
	    , formattedDateTime
	    ;

	  year = now.getFullYear();
	  month = now.getMonth().toString().length === 1 ? '0' + (now.getMonth() + 1).toString() : now.getMonth() + 1;
	  date = now.getDate().toString().length === 1 ? '0' + (now.getDate()).toString() : now.getDate();
	  hours = now.getHours().toString().length === 1 ? '0' + now.getHours().toString() : now.getHours();
	  minutes = now.getMinutes().toString().length === 1 ? '0' + now.getMinutes().toString() : now.getMinutes();
	  seconds = '00';
	  formattedDateTime = year + '-' + month + '-' + date + 'T' + hours + ':' + minutes + ':' + seconds;

	  if ( onlyBlank === true && $(this).val() ) {
	    return this;
	  }

	  $(this).val(formattedDateTime);

	  return this;
	}

$( document ).ready(function() {
	    // Handler for .ready() called.
	    $('input[type="datetime"]').setNow();
		$("#poczatek").setNow();
		$("#koniec").setNow();
	});
</script>

<script type="text/javascript">
$(document).ready(function()
{
   /*  $("#opis").keyup(function()
     {
          var max = 65535
          var box=$(this).val();
          var main = box.length *100;
          var value= (main / max);
          var count= max - box.length;

          if(box.length <= max)
          {
               $('#count').html(count);
               $('#bar').animate(
               {
                    "width": value+'%',
               }, 1);
          }
          else
          {
               $(this).val($(this).val().substring(0,max - 1));
          }
          return false;
     });*/

	$('textarea#opis').maxlength({
        alwaysShow: true
    });
});
</script>
<script type="text/javascript" src="js/bootstrap-maxlength.js" />
<style>
#bar
{
background-color:#a71e2b;
width:0px;
height:16px;
}
#barbox
{
/*float:right;*/
height:16px;
background-color:#FFFFFF;
width:100px;
border:solid 2px #000;
margin-right:3px;
-webkit-border-radius:5px;-moz-border-radius:5px;
}
#count
{
float:right; margin-right:8px;
font-family:'Georgia', Times New Roman, Times, serif;
font-size:16px;
font-weight:bold;
/*color:#666666*/
color: white;
}
#opis
{
/*width:450px; height:50px;*/
border:solid 2px #006699;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
</style>


<%
SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						InvitationMethods inv_m = new InvitationMethods();
						 Integer user_id = (Integer) session.getAttribute("user_id");
							UserMethods u_m = new UserMethods();
							LocalMethods lm = new LocalMethods();
							User u = u_m.id_to_user(sessionFactory, s, user_id);
							%>
<br />

<div id="content">
<form action="../addEvent" method="POST" name='form1'>

<input type="hidden" id="organizator" name="organizator" value="<%=u.getUser_id()%>" />
			<table>
			<tr>
			<td>
			Nazwa wydarzenia
			</td>
			<td>
			<input type="text" id="eventName" name="eventName" />
			</td>
			</tr>
			
			<tr>
			<td>
			Lokal:
			</td>
			<td>
			<% List<Local> locals = lm.listAllLocals(sessionFactory, s); 
				if (locals.size() > 0) {%> 
			<select id="local" name="local" style="width:300px;">
			<% 	for (Local c : locals) {
					int id = c.getLocal_id();
					String catname = c.getCountry()+", "+ c.getCity()+", "+ c.getStreet()+" "+c.getLocal_number();%>
			<option value="<%=id%>"><%=catname%></option>
			<%}
				
			}
			if (locals.size() == 0) {
		 out.println("Nie ma zadnych lokali w bazie");
		
			} %>
			</select>
			</td>
			</tr>
			
			
			<tr>
			<td>
			Poczatek wydarzenia
			</td>
			<td>
			<input type="datetime-local" id="poczatek" name="poczatek" />
			</td>
			</tr>
			
			
			<tr>
			<td>
			Koniec wydarzenia
			</td>
			<td>
			<input type="datetime-local" id="koniec" name="koniec" />
			</td>
			</tr>
			
			<tr>
			<td>
			Opis wydarzenia
			</td>
			<td>
			<textarea rows="5" cols="25" id="opis" name="opis"></textarea>
			</td>
			</tr>
			<!-- <tr>
			<td>
			</td>
			<td>
			<br />
			Pozostało znaków:
<div id="count">65535</div>
<div id="barbox"><div id="bar"></div></div>

</td>
			
			</tr> -->
			<tr>
			<td>
			Wielokrotna rozgrywka
			</td>
			<td>
			<input type="checkbox" id="multiple" name="multiple" />
			</td>
			</tr>
			
			<tr>
			<td>
			<input type="submit" class="mainBtn" value="Dodaj wydarzenie" />
			</td>
			</tr>
</table>
</form>
</div>
